<?php

namespace common\components\wtools\validators;

use yii\validators\Validator;

class Password extends Validator
{
    public function validateAttribute($model, $attribute)
    {
        $password = $model->$attribute;
        $r = "/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&-_])[A-Za-z\d@$!%*?&-_]{8,}$/";
        if (!preg_match($r, $password)) {
            $this->addError($model, $attribute, '密码格式错误：必须包含大小写字母数字和特殊符号，并且长度大于8位');
        }
    }
}
